package com.glxy.service.impl;

import com.glxy.dao.impl.BillDaoImpl;
import com.glxy.dao.impl.UserDaoImpl;
import com.glxy.pojo.Bill;
import com.glxy.service.BillService;

import java.util.ArrayList;

public class BillServiceImpl implements BillService {

    public ArrayList<Bill> findBill(String productName) {
        return new BillDaoImpl().findByName(productName);
    }

    @Override
    public Integer totalCount(){
        return new BillDaoImpl().findAll().size();
    }
    @Override
    public ArrayList<Bill> findAllBillPages(Integer pageSize, Integer pageNo){
        ArrayList<Bill> page =  new ArrayList<>();
        ArrayList<Bill> list = new BillDaoImpl().findAll();

        for (int i = pageSize*(pageNo - 1); i < pageSize*(pageNo - 1) + pageSize; i++) {
            if (i < list.size()) page.add(list.get(i));
        }
        return page;
    }

    @Override
    public ArrayList<Bill> getBillList() {
        BillDaoImpl billDao = new BillDaoImpl();
        return billDao.findAll();
    }

    @Override
    public boolean insertBill(Bill bill) {
        return new BillDaoImpl().insert(bill);
    }

    public void update(Bill bill) {
        BillDaoImpl billDao = new BillDaoImpl();
        billDao.update(bill);
    }

    @Override
    public boolean delete(Long id) {
        return new BillDaoImpl().delete(id);
    }
}
